home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Misc Servers / Zope.exe / NULLRESOURCE.PY < prev    next >
Encoding:
Python Source  |  1999-10-08  |  7.1 KB  |  173 lines

  1. ##############################################################################
  2. # Zope Public License (ZPL) Version 1.0
  3. # -------------------------------------
  4. # Copyright (c) Digital Creations.  All rights reserved.
  5. # This license has been certified as Open Source(tm).
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions are
  8. # met:
  9. # 1. Redistributions in source code must retain the above copyright
  10. #    notice, this list of conditions, and the following disclaimer.
  11. # 2. Redistributions in binary form must reproduce the above copyright
  12. #    notice, this list of conditions, and the following disclaimer in
  13. #    the documentation and/or other materials provided with the
  14. #    distribution.
  15. # 3. Digital Creations requests that attribution be given to Zope
  16. #    in any manner possible. Zope includes a "Powered by Zope"
  17. #    button that is installed by default. While it is not a license
  18. #    violation to remove this button, it is requested that the
  19. #    attribution remain. A significant investment has been put
  20. #    into Zope, and this effort will continue if the Zope community
  21. #    continues to grow. This is one way to assure that growth.
  22. # 4. All advertising materials and documentation mentioning
  23. #    features derived from or use of this software must display
  24. #    the following acknowledgement:
  25. #      "This product includes software developed by Digital Creations
  26. #      for use in the Z Object Publishing Environment
  27. #      (http://www.zope.org/)."
  28. #    In the event that the product being advertised includes an
  29. #    intact Zope distribution (with copyright and license included)
  30. #    then this clause is waived.
  31. # 5. Names associated with Zope or Digital Creations must not be used to
  32. #    endorse or promote products derived from this software without
  33. #    prior written permission from Digital Creations.
  34. # 6. Modified redistributions of any form whatsoever must retain
  35. #    the following acknowledgment:
  36. #      "This product includes software developed by Digital Creations
  37. #      for use in the Z Object Publishing Environment
  38. #      (http://www.zope.org/)."
  39. #    Intact (re-)distributions of any official Zope release do not
  40. #    require an external acknowledgement.
  41. # 7. Modifications are encouraged but must be packaged separately as
  42. #    patches to official Zope releases.  Distributions that do not
  43. #    clearly separate the patches from the original work must be clearly
  44. #    labeled as unofficial distributions.  Modifications which do not
  45. #    carry the name Zope may be packaged in any form, as long as they
  46. #    conform to all of the clauses above.
  47. # Disclaimer
  48. #   THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
  49. #   EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  50. #   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  51. #   PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
  52. #   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  53. #   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  54. #   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  55. #   USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  56. #   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  57. #   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  58. #   OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  59. #   SUCH DAMAGE.
  60. # This software consists of contributions made by Digital Creations and
  61. # many individuals on behalf of Digital Creations.  Specific
  62. # attributions are listed in the accompanying credits file.
  63. ##############################################################################
  64.  
  65. """WebDAV support - null resource objects."""
  66.  
  67. __version__='$Revision: 1.23 $'[11:-2]
  68.  
  69. import sys, os, string, mimetypes, Globals
  70. import Acquisition, OFS.content_types
  71. from common import absattr, aq_base, urlfix
  72. from AccessControl.Permission import Permission
  73. from Resource import Resource
  74. from Globals import Persistent
  75.  
  76.  
  77. class NullResource(Persistent, Acquisition.Implicit, Resource):
  78.     """Null resources are used to handle HTTP method calls on
  79.     objects which do not yet exist in the url namespace."""
  80.  
  81.     __null_resource__=1
  82.  
  83.     __ac_permissions__=(
  84.         ('View',                             ('HEAD',)),
  85.         ('Add Documents, Images, and Files', ('PUT',)),
  86.         ('Add Folders',                      ('MKCOL',)),
  87.     )
  88.  
  89.     def __init__(self, parent, name, request=None):
  90.         self.__name__=name
  91.         self.__parent__=parent
  92.  
  93.     def __bobo_traverse__(self, REQUEST, name=None):
  94.         # We must handle traversal so that we can recognize situations
  95.         # where a 409 Conflict must be returned instead of the normal
  96.         # 404 Not Found, per [WebDAV 8.3.1].
  97.         try:    return getattr(self, name)
  98.         except: pass
  99.         method=REQUEST.get('REQUEST_METHOD', 'GET')
  100.         if method in ('PUT', 'MKCOL'):
  101.             raise 'Conflict', 'Collection ancestors must already exist.'
  102.         raise 'Not Found', 'The requested resource was not found.'
  103.  
  104.     def HEAD(self, REQUEST, RESPONSE):
  105.         """Retrieve resource information without a response message body."""
  106.         self.dav__init(REQUEST, RESPONSE)
  107.         raise 'Not Found', 'The requested resource does not exist.'
  108.  
  109.     # Most methods return 404 (Not Found) for null resources.
  110.     DELETE=OPTIONS=TRACE=PROPFIND=PROPPATCH=COPY=MOVE=HEAD
  111.  
  112.     def PUT(self, REQUEST, RESPONSE):
  113.         """Create a new non-collection resource."""
  114.         self.dav__init(REQUEST, RESPONSE)
  115.         type=REQUEST.get_header('content-type', None)
  116.         body=REQUEST.get('BODY', '')
  117.         name=self.__name__
  118.         if type is None:
  119.             type, enc=OFS.content_types.guess_content_type(name, body)
  120.         from OFS.Image import Image, File
  121.         if type in ('text/html', 'text/xml', 'text/plain'):
  122.             self.__parent__.manage_addDTMLDocument(name, '', body)
  123.         elif type[:6]=='image/':
  124.             ob=Image(name, '', body, content_type=type)
  125.             self.__parent__._setObject(name, ob)
  126.         else:
  127.             ob=File(name, '', body, content_type=type)
  128.             self.__parent__._setObject(name, ob)
  129.         RESPONSE.setStatus(201)
  130.         RESPONSE.setBody('')
  131.         return RESPONSE
  132.  
  133.     def MKCOL(self, REQUEST, RESPONSE):
  134.         """Create a new collection resource."""
  135.         self.dav__init(REQUEST, RESPONSE)
  136.         if REQUEST.get('BODY', ''):
  137.             raise 'Unsupported Media Type', 'Unknown request body.'
  138.         parent=self.__parent__
  139.         name=self.__name__
  140.         if hasattr(aq_base(parent), name):
  141.             raise 'Method Not Allowed', 'The name %s is in use.' % name
  142.         if not hasattr(parent, '__dav_collection__'):
  143.             raise 'Forbidden', 'Cannot create collection at this location.'
  144.         parent.manage_addFolder(name)
  145.         RESPONSE.setStatus(201)
  146.         RESPONSE.setBody('')
  147.         return RESPONSE
  148.  
  149.  
  150.  
  151. Globals.default__class_init__(NullResource)
  152.